<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增需求')" />
	<th:block th:include="include :: select2-css" />
	<th:block th:include="include :: summernote-css" />
	<th:block th:include="include :: bootstrap-select-css" />
</head>
<body>
	<div class="main-content">
		<form id="form-busReq-add" class="form-horizontal">
			<input id="treeId" name="reqType" type="hidden"/>
			<input id="deptId" name="publishDeptId" type="hidden" />
			<h4 class="form-header h4">基本信息</h4>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">所属组织：</label>
						<div class="col-sm-8">
							<div class="input-group">
								<input name="publishDeptName" onclick="selectDeptTree()" id="deptName" type="text" placeholder="请选择所属组织" class="form-control">
								<span class="input-group-addon"><i class="fa fa-search"></i></span>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label is-required">需求名称：</label>
						<div class="col-sm-8">
							<input name="reqName" placeholder="请输入资源名称" class="form-control" type="text" maxlength="200" required>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label is-required">需求分类：</label>
						<div class="col-sm-8">
							<div class="input-group">
								<input name="typeName" onclick="selectTypeTree()" id="treeName" type="text" placeholder="请选择需求分类" class="form-control">
								<span class="input-group-addon"><i class="fa fa-search"></i></span>
							</div>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-xs-4 control-label">需求标签：</label>
						<div class="col-sm-8">
							<input name="label" placeholder="请输入需求标签，多个用“，”分割" class="form-control" type="text" maxlength="200" required>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-xs-4 control-label">需求内容：</label>
						<div class="col-xs-8">
							<textarea id="content" name="content" maxlength="500" class="form-control" rows="5"></textarea>
						</div>
					</div>
				</div>
			</div>
			<!--
			<h4 class="form-header h4">详细内容</h4>
			<div class="row">
				<div class="col-sm-12">
					<div class="ibox float-e-margins">
						<div class="ibox-title">
							<button id="edit" class="btn btn-primary btn-xs m-l-sm" onclick="editContent()" type="button">编辑</button>
							<button id="save" class="btn btn-primary  btn-xs" onclick="saveContent()" type="button">保存</button>
						</div>
						<div class="ibox-content" id="content">

							<div class="click2edit wrapper">
								<p>
									请输入内容...
								</p>
							</div>

						</div>
					</div>
				</div>
			</div>
			-->
		</form>
	</div>

	<div class="row">
		<div class="col-sm-offset-5 col-sm-10">
			<button type="button" class="btn btn-sm btn-warning" onclick="saveHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
			<button type="button" class="btn btn-sm btn-primary" onclick="publishHandler()"><i class="fa fa-check"></i>发 布</button>&nbsp;
			<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: select2-js" />
	<th:block th:include="include :: summernote-js" />
	<th:block th:include="include :: bootstrap-select-js" />




    <script type="text/javascript">
		var prefix = ctx + "system/busReq"
		$("#form-busReq-add").validate({
			rules:{
				xxxx:{
					required:true,
				},
			},
			focusCleanup: true
		});

		/** 保存为待发布 */
		function saveHandler() {
	        if ($.validate.form()) {
				var data = $("#form-busReq-add").serializeArray();
				data.push({"name": "status", "value": "00"});
	            $.operate.save(prefix + "/add", data);
	        }
	    }

		/** 保存为已发布 */
		function publishHandler() {
			if ($.validate.form()) {
				var data = $("#form-busReq-add").serializeArray();
				data.push({"name": "status", "value": "01"});
				$.operate.save(prefix + "/add", data);
			}
		}

		/*资源管理-新增-选择资源分类*/
		function selectTypeTree() {
			var treeId = $("#treeId").val();
			var typeId = treeId > 0 ? treeId : 1;
			var url = ctx + "system/busResourceType/selectTypeTree/" + typeId;
			var options = {
				title: '类型选择',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}

		function doSubmit(index, layero){
			var body = layer.getChildFrame('body', index);
			$("#treeId").val(body.find('#treeId').val());
			$("#treeName").val(body.find('#treeName').val());
			layer.close(index);
		}


		/* 资源管理-新增-选择所属组织 */
		function selectDeptTree() {
			var deptId = $("#deptId").val();
			var publishDeptId = $.common.isEmpty(deptId) ? "100" : $("#deptId").val();
			var url = ctx + "system/dept/selectDeptTree/" + publishDeptId;
			var options = {
				title: '选择组织',
				width: "380",
				url: url,
				callBack: doSubmitDept
			};
			$.modal.openOptions(options);
		}

		function doSubmitDept(index, layero){
			var tree = layero.find("iframe")[0].contentWindow.$._tree;
			var body = layer.getChildFrame('body', index);
			$("#deptId").val(body.find('#treeId').val());
			$("#deptName").val(body.find('#treeName').val());
			layer.close(index);
		}

		/**编辑需求内容*/
		var editContent = function () {
			$("#content").addClass("no-padding");
			$('.click2edit').summernote({
				lang: 'zh-CN',
				focus: true
			});
		};
		/**保存资源内容*/
		var saveContent = function () {
			$("#content").removeClass("no-padding");
			var aHTML = $('.click2edit').summernote('code');
			$('.click2edit').summernote('destroy');
		};

	</script>
</body>
</html>
